package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ExtentGroupDao;
import cn.topevery.garden.dal.dao.ExtentGroupUserDao;
import cn.topevery.garden.entity.po.ExtentGroup;
import cn.topevery.garden.entity.po.ExtentGroupUser;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Service
public class ExtentGroupLogic extends BaseLogic<ExtentGroup> {
    @Autowired
    ExtentGroupDao extentGroupDao;

    @Autowired
    ExtentGroupUserDao extentGroupUserDao;

    @Override
    public BaseEntityDao<ExtentGroup, Integer> getDao() {
        return extentGroupDao;
    }


    /**
     * 描述 保存群组信息
     *
     * @param userId the user id
     * @return the boolean
     * @author wenzhao.lin
     * @created 2021 -08-23 14:02:35 Save or update boolean.
     */
    public boolean saveOrUpdate(String userId, Integer extentId, List<ExtentGroup> list){
        if(list != null){
            for(ExtentGroup entity : list){
                entity.setExtentId(extentId);
                extentGroupDao.saveOrUpdate(userId, entity);

                saveGroupUser(userId, entity.getId(), entity.getGroupUserList());
            }
        }

        return true;
    }

    /**
     * 描述 保存群组用户
     *
     * @param userId the user id
     * @return the boolean
     * @author wenzhao.lin
     * @created 2021 -08-23 14:02:35 Save or update boolean.
     */
    public  boolean saveGroupUser(String userId,Integer groupId, List<ExtentGroupUser> list){
        if(list != null){
            for(ExtentGroupUser entity : list){
                entity.setGroupId(groupId);
                extentGroupUserDao.saveOrUpdate(userId, entity);
            }
        }

        return true;
    }

}
